package com.eshop.modules.mp.service.impl;

import java.lang.invoke.SerializedLambda;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import java.io.IOException;
import java.util.Iterator;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.eshop.utils.FileUtil;
import java.util.ArrayList;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.eshop.common.utils.QueryHelpPlus;
import com.eshop.modules.mp.service.dto.WechatMenuDto;
import java.util.LinkedHashMap;
import java.util.List;
import com.github.pagehelper.PageInfo;
import java.util.Map;
import org.springframework.data.domain.Pageable;
import com.eshop.modules.mp.service.dto.WechatMenuQueryCriteria;
import com.eshop.dozer.service.IGenerator;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import com.eshop.modules.mp.service.WechatMenuService;
import com.eshop.modules.mp.domain.WechatMenu;
import com.eshop.modules.mp.service.mapper.WechatMenuMapper;
import com.eshop.common.service.impl.BaseServiceImpl;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = { Exception.class })
public class WechatMenuServiceImpl extends BaseServiceImpl<WechatMenuMapper, WechatMenu> implements WechatMenuService
{
    private final IGenerator generator;
    
    public Map<String, Object> queryAll(final WechatMenuQueryCriteria criteria, final Pageable pageable) {
        this.getPage(pageable);
        final PageInfo<WechatMenu> page = (PageInfo<WechatMenu>)new PageInfo((List)this.queryAll(criteria));
        final Map<String, Object> map = new LinkedHashMap<String, Object>(2);
        map.put("content", this.generator.convert(page.getList(), (Class)WechatMenuDto.class));
        map.put("totalElements", page.getTotal());
        return map;
    }
    
    public List<WechatMenu> queryAll(final WechatMenuQueryCriteria criteria) {
        return (List<WechatMenu>)((WechatMenuMapper)this.baseMapper).selectList((Wrapper)QueryHelpPlus.getPredicate(WechatMenu.class, criteria));
    }
    
    public void download(final List<WechatMenuDto> all, final HttpServletResponse response) throws IOException {
        final List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        for (final WechatMenuDto yxWechatMenu : all) {
            final Map<String, Object> map = new LinkedHashMap<String, Object>();
            map.put("缓存数据", yxWechatMenu.getResult());
            map.put("缓存时间", yxWechatMenu.getAddTime());
            list.add(map);
        }
        FileUtil.downloadExcel((List)list, response);
    }
    
    public Boolean isExist(final String wechat_menus) {
        final WechatMenu wechatMenu = (WechatMenu)this.getOne((Wrapper) Wrappers.<WechatMenu>lambdaQuery().eq(WechatMenu::getKey, wechat_menus));
        if (wechatMenu == null) {
            return false;
        }
        return true;
    }
    
    public WechatMenuServiceImpl(final IGenerator generator) {
        this.generator = generator;
    }
}
